package PTA.javaA;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class ex20 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=Integer.valueOf(sc.nextLine());
        ArrayList<PersonSortable> list=new ArrayList();
        for (int i=0;i<n;i++){
            String string[]=sc.nextLine().split(" ");
            list.add(new PersonSortable(string[0],Integer.valueOf(string[1])));
        }
        Collections.sort(list);
        for (PersonSortable p:list){
            System.out.println(p);
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

    }
}
class PersonSortable implements  Comparable{
 private int age;
 private String name;
 public PersonSortable(){
     this.name = name;
     this.age=age;

 }
 public PersonSortable(String name,int age){
     this.name = name;
     this.age= age;
 }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name+"-"+age;
    }

    @Override
    public int compareTo(Object o) {
        PersonSortable per=(PersonSortable)o;
        int x = this.name.compareTo(per.name);
        //相同 x=0
        if(x!=0){
            return x;
        }else{
            if (this.age>per.age) {
                return 1;
            } else if(this.age<per.age) {
                return -1;
            } else {
                return 0;
            }

    }
 }
}